//
//  L&RViewModel.m
//  B2C
//
//  Created by fyanyan on 2018/7/30.
//  Copyright © 2018年 lixiaolong. All rights reserved.
//

#import "L&RViewModel.h"

@interface L_RViewModel()

@property(strong,nonatomic) RACSignal *userNameSignal;
@property(strong,nonatomic) RACSignal *passwordSignal;
@property(strong,nonatomic) RACSignal *codeNumSignal;
@property(strong,nonatomic) RACSignal *password_AgainSignal;

@end


#define KUserName @"userName"
#define KPassWord @"password"

@implementation L_RViewModel

-(instancetype)init{
    if (self = [super init]) {
        [self initialize];
    }
    return self;
}

- (void)initialize {
    _userNameSignal = RACObserve(self, userName);
    _passwordSignal = RACObserve(self, password);
    _codeNumSignal = RACObserve(self, codeNum);
    _password_AgainSignal = RACObserve(self, password_Again);
}

#pragma mark -- 登录按钮状态
-(id)buttpnIsValid{
    RACSignal *isValid = [RACSignal combineLatest:@[_userNameSignal,_passwordSignal] reduce:^id (NSString *userName, NSString *password){
        return @(userName.length >= 3 && (password.length >= 6 && password.length <17));
    }];
    return isValid;
}

#pragma mark -- 注册按钮的状态
-(id)registerBtnIsValid{
    RACSignal *isValid = [RACSignal combineLatest:@[_userNameSignal,_passwordSignal,_password_AgainSignal,_codeNumSignal] reduce:^id (NSString *userName, NSString *password,NSString *password_again,NSString *codeNum){
        return @(userName.length >= 3 && (password.length >= 6 && password.length <17) && (password == password_again) && (codeNum.length > 0) );
    }];
    return isValid;
}

#pragma mark -- 获取验证码的按钮的状态
-(id)getCodeBtnIsValid{
    RACSignal *isValid = [RACSignal combineLatest:@[_userNameSignal] reduce:^id (NSString *userName){
        return @(userName.length == 11 && [LXLIsPhoneNumber valiMobile:userName]);
    }];
    return isValid;
}
@end
